<template>
  <div pop class="gonggaoCont" v-show="show">
    <div class="cont">
      <div class="gonggaoclose" @click.stop="hideCont"></div>
      <swiper :showDots='contList.length>1' :dotsPosition='"center"' :auto='true' :interval='8000' class='swiper-container' v-if="contList.length>0">
        <swiper-item v-for='(item, index) in contList' :key='index' >
          <div class="text">
            <div class="cont-title">{{item.title}}</div>
            <div class="cont-text">{{item.text}}</div>
          </div>
        </swiper-item>
      </swiper>
    </div>
  </div>
</template>

<script>
  import store from 'store/store'
  import { Swiper, SwiperItem } from 'components/swiper'
  import Constant from 'common/constant'
  import RemoteDAO from 'common/RemoteDAO'

  export default {
    data () {
      return {
        mySwiper: {},
        contList: []
      }
    },
    computed: {
      show () {
        return store.state.showGonggao
      }
    },
    components: {
      Swiper,
      SwiperItem
    },
    watch: {
      show: 'showCont'
    },
    methods: {
      showCont () {
        if (this.show) {
          // 获取公告
          RemoteDAO.callUC12000054({relationId: Constant.GLDH_ID}).then(res => {
            let arr = res.data.body
            for (let i = 0; i < arr.length && i < 6; i++) {
              this.contList.push({title: '', text: ''})
              this.contList[i].title = arr[i].NOTICE_TITLE
              this.contList[i].text = arr[i].NOTICE_TEXT
            }
          }, error => {
            this.$store.dispatch('setTip', {text: error.message})
          })
        }
      },
      hideCont () {
        this.$store.dispatch('setShowGonggao', false)
        this.contList = []
      }
    }
  }
</script>
<style scoped>
  .gonggaoCont .swiper-container{
    width: 437px;
    height: 385px;
    top:110px;
  }
</style>
